<?php
namespace Admin\Controller;

use Think\Controller;

class TestController extends Controller {
	
	/**
	 * 更新类别配置
	 */
	public function updateClassConfigAction() {
		$attrs = M("product_attribute")->select();
		foreach ($attrs as $k => $v) {
			$data = array();
			$values = explode(',', trim($v['values'], ","));
			foreach ( $values as $v0 ) {
				list($a, $b) = explode("|", $v0);
				$data[$a] = $b;
			}
			$v['config'] = serialize(array(
				'type' => 'checkbox',
				'auto_value' => 1,
				'data' => $data,
				'wparam' => array(),
				'operate' => 1,
			));
			M("product_attribute")->where(array('id'=>$v['id']))->setField("config", $v['config']);
		}
	}
	
	public function fixDistributionShopUserTreeLengthAction(){
	    $model = M("DistributionShopUserTree");
	    
	    $model->where(array('length'=>0));
	    $model->field("id,tree,length");
	    $lists = $model->select();
	    
	    $count = 0;
	    foreach ($lists as $v){
	        $rows = $model->where(array('id'=>$v['id']))->setField("length",count(explode(',', $v['tree'])));
	        $rows && $count++;
	    }
	    
	    echo $count;
	}
	
}